class PspDataController {
	
	def authenticateService
	
	User currentUser = new User()
	
	def index = {
		redirect(action: "list", params: params)
	}
	
	def list = {
		def authPrincipal = authenticateService.principal()
		currentUser = User.findByUsername(authPrincipal.username)
		List projectList = new ArrayList()
		for(projectTeam in currentUser.projectTeams){
			projectList.add (projectTeam.project)
		}
		session.projectList = projectList
		
		if (params.project) {
			def project = Project.findById(params.project.id)
			
			// keep current project into the session
			session.project = project
			session.projectTeams = ProjectTeam.findAllByProject(project)
			
			[project: project]
		}
	}
	
	def show = {
		if (params.userId) {
			def task = Task.findById(params.taskId)
			def user = User.findById(params.userId)
			def pspDataList = PspData.findAllByUserAndTask(user,task)
			[pspDataList: pspDataList, user: user, task: task]
		}
	}
}
